$(function() {
	// ##### string formater instalation #####
	if (!String.prototype.format) {
		String.prototype.format = function() {
			var args = arguments;
			return this.replace(/{(\d+)}/g, function(match, number) { 
				return typeof args[number] != 'undefined'
					? args[number]
					: match;
			});
		};
	};
	
	if (!String.prototype.cut) {
		String.prototype.cut = function(n) {
		    var cut= this.indexOf(' ', n);
		    if(cut== -1) return this;
		    return this.substring(0, cut);
		};
	};
	
	// ##### Prevents reloading ##### // skomentowane bo wkurza podczas kodzenia :)
//	$(window).bind({
//        beforeunload: function(ev) {
//            ev.preventDefault();
//            return "Your data will be lost forever!";
//        },
//        unload: function(ev) {
//            ev.preventDefault();
//            return "Your data will be lost forever!";
//        }
//    });
	var $mainContainer = $("#note_container");
	
	AJAXConfiguration.init();
	MainContent.init($mainContainer);
	
	//test
	var HashTagTest = {loader:function(c){return function(o){c.html("udalo sie<br/>Zaladowano "+o.name+
			"<br/><a href='"+o.url+"'>"+o.name+"</a>");};}};
	//end of test
	
//	var sideContainer = {
//			userHashTagsTab: null,		//tagi ktore obserwuje uzytkownik
//			subscribtionsTab: null,		//uzytkownicy ktorych obserwuje uzytkownik (po kliknieciu na nich pokazywane sa wpisy)
//			popularHashTagsTab: null,	//tagi posortowane po popularnosci
//			popularHashTagsTab: null	//ranking
//	};
	var logonFormContainers = {
			$logonForm: $("#logon_form"),
			$loginButton: $("#login_button"),
			$logoutButton: $("#logout_button"),
			$openFormButton: $("#open_logon_form"),
			$closeFormButton: $("#close_logon_form"),
			$userKeyInput: $("#user_key_field")
	};
	
	LogonForm.init(logonFormContainers);
	UserLogon.registerUserLogonObserver(LogonForm);
//	HashTags.download();
	
	initSearchEngine($("#search_test"), $mainContainer, {
		profileLoader: Profiles.loadBig,
		hashTagLoader: HashTagTest.loader,
		entryLoader: Entries.loadNormal
	});
	
	MainContent.append(new Microblog().getComponent());
	MainContent.show();
	
	$("#page_title").css( 'cursor', 'pointer' );
	$("#page_title").click(function() {
		MainContent.clear();
		MainContent.append(new Microblog().getComponent());
		MainContent.show();
	});
});